package org.dromara.pe.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.pe.domain.bo.DeviceApiBo;
import org.dromara.pe.domain.bo.ScopeSettingBo;
import org.dromara.pe.domain.vo.DeviceApiVo;
import org.dromara.pe.domain.vo.ScopeSettingVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.pe.domain.vo.AreaVo;
import org.dromara.pe.domain.bo.AreaBo;
import org.dromara.pe.service.IAreaService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 体育场地设置
 *
 * @author Lion Li
 * @date 2024-09-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pe/area")
public class AreaController extends BaseController {

    private final IAreaService areaService;

    /**
     * 查询体育场地设置列表
     */
    @SaCheckPermission("pe:area:list")
    @GetMapping("/list")
    public TableDataInfo<AreaVo> list(AreaBo bo, PageQuery pageQuery) {
        return areaService.queryPageList(bo, pageQuery);
    }


    @SaCheckPermission("pe:area:query")
    @GetMapping("/infoList")
    public R<List<AreaVo>> getInfoList(AreaBo bo) {
        return R.ok(areaService.queryList(bo));
    }

    /**
     * 导出体育场地设置列表
     */
    @SaCheckPermission("pe:area:export")
    @Log(title = "体育场地设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AreaBo bo, HttpServletResponse response) {
        List<AreaVo> list = areaService.queryList(bo);
        ExcelUtil.exportExcel(list, "体育场地设置", AreaVo.class, response);
    }

    /**
     * 获取体育场地设置详细信息
     *
     * @param areaId 主键
     */
    @SaCheckPermission("pe:area:query")
    @GetMapping("/{areaId}")
    public R<AreaVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long areaId) {
        return R.ok(areaService.queryById(areaId));
    }

    /**
     * 新增体育场地设置
     */
    @SaCheckPermission("pe:area:add")
    @Log(title = "体育场地设置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AreaBo bo) {
        return toAjax(areaService.insertByBo(bo));
    }

    /**
     * 修改体育场地设置
     */
    @SaCheckPermission("pe:area:edit")
    @Log(title = "体育场地设置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AreaBo bo) {
        return toAjax(areaService.updateByBo(bo));
    }

    /**
     * 删除体育场地设置
     *
     * @param areaIds 主键串
     */
    @SaCheckPermission("pe:area:remove")
    @Log(title = "体育场地设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{areaIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] areaIds) {
        return toAjax(areaService.deleteWithValidByIds(List.of(areaIds), true));
    }
}
